﻿<navigation:Page 
           x:Class="AdminModule.Views.ViewData" 
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
           xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
           xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
           mc:Ignorable="d"
           xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
           xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
           xmlns:viewmodel="clr-namespace:AdminModule.ViewModels"
           xmlns:classes="clr-namespace:AdminModule.CustomXAMLElements"
           xmlns:usercontrols="clr-namespace:AdminModule.UserControls.Common"
           xmlns:converter="clr-namespace:AdminModule.Converters"
           xmlns:dataprimitives="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls.Data"
           xmlns:root="clr-namespace:AdminModule"
           d:DesignWidth="640" d:DesignHeight="480"
           Title="Просмотр данных">

    <UserControl.Resources>
        <viewmodel:ViewDataVM x:Key="viewDataViewModel"/>
        <converter:DateTimeConverter x:Key="dateTimeConverter" />
        <converter:EmptyStringToVisibleConverter x:Key="emptyStringToVisibleConverter" />
        <root:Settings x:Key="settings"></root:Settings>

        <Style x:Key="infoColumnStyle" TargetType="dataprimitives:DataGridColumnHeader">
            <Setter Property="FontStyle" Value="Italic"/>
        </Style>

        <classes:ColumnCollection x:Key="AdmPerson">
            <data:DataGridTextColumn Binding="{Binding LastName}" Header="Фамилия"/>
            <data:DataGridTextColumn Binding="{Binding FirstName}" Header="Имя"/>
            <data:DataGridTextColumn Binding="{Binding Patronymic}" Header="Отчество"/>
            <data:DataGridTextColumn Binding="{Binding EMail}" Header="Адрес электронной почты"/>
        </classes:ColumnCollection>

        <classes:ColumnCollection x:Key="AdmDegree">
            <data:DataGridTextColumn Binding="{Binding Name}" Header="Название"/>
        </classes:ColumnCollection>

        <classes:ColumnCollection x:Key="AdmCategoriesByTerm">
            <data:DataGridTemplateColumn Header="">
                <data:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <Image Source="{Binding ImagePath}"></Image>
                    </DataTemplate>
                </data:DataGridTemplateColumn.CellTemplate>
            </data:DataGridTemplateColumn>
            <data:DataGridTextColumn Binding="{Binding Name}" Header="Категория"/>
            <data:DataGridTextColumn Binding="{Binding Weight}" Header="Вес"/>
            <data:DataGridTextColumn Binding="{Binding CharacteristicsCount}" HeaderStyle="{StaticResource infoColumnStyle}" Header="Количество показателей"/>
        </classes:ColumnCollection>

        <classes:ColumnCollection x:Key="AdmJob">
            <data:DataGridTextColumn Binding="{Binding Position.Name}" Header="Должность"/>
            <data:DataGridTextColumn Binding="{Binding Status.Order}" Header="Ставка"/>
        </classes:ColumnCollection>

        <classes:ColumnCollection x:Key="AdmDepartmentType">
            <data:DataGridTextColumn Binding="{Binding Name}" Header="Название"/>
            <data:DataGridTextColumn Binding="{Binding DepartmentsCount}" HeaderStyle="{StaticResource infoColumnStyle}" Header="Количество отделов"/>
        </classes:ColumnCollection>

        <classes:ColumnCollection x:Key="AdmPosition">
            <data:DataGridTextColumn Binding="{Binding Order}" Header="Номер"/>
            <data:DataGridTextColumn Binding="{Binding Name}" Header="Должность"/>
            <data:DataGridTemplateColumn Header="Общая по университету">
                <data:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <CheckBox VerticalAlignment="Center" HorizontalAlignment="Center" IsEnabled="False" IsChecked="{Binding IsTotal}"></CheckBox>
                    </DataTemplate>
                </data:DataGridTemplateColumn.CellTemplate>
            </data:DataGridTemplateColumn>
            <data:DataGridTextColumn Binding="{Binding SID}" Header="SID"/>
            <data:DataGridTemplateColumn Header="">
                <data:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <Button Visibility="{Binding Path=SID, Converter={StaticResource emptyStringToVisibleConverter}}" Tag="{Binding}" Margin="0,0,0,0" ToolTipService.ToolTip="Найти имя по SID" Width="24" Height="24" x:Name="SIDToNameButton" Click="SIDToNameButton_Click">
                            <Image Source="/AdminModule;Component/Images/Find.png"></Image>
                        </Button>
                    </DataTemplate>
                </data:DataGridTemplateColumn.CellTemplate>
            </data:DataGridTemplateColumn>
            <data:DataGridTextColumn Binding="{Binding SIDToName, Mode=TwoWay}" Header="Имя по SID"/>
        </classes:ColumnCollection>

        <classes:ColumnCollection x:Key="AdmStatus">
            <data:DataGridTextColumn Binding="{Binding Order}" Header="Ставка"/>
        </classes:ColumnCollection>

        <classes:ColumnCollection x:Key="AdmResponsible">
            <data:DataGridTextColumn Binding="{Binding Position.Name}" Header="Должность"/>
            <data:DataGridTextColumn Binding="{Binding Department.FullName}" Header="Отдел"/>
        </classes:ColumnCollection>

        <classes:ColumnCollection x:Key="AdmTerm">
            <data:DataGridTextColumn Binding="{Binding Order}" Header="Номер"/>
            <data:DataGridTextColumn Header="Дата начала периода">
                <data:DataGridTextColumn.Binding>
                    <Binding Path="Start" Converter="{StaticResource dateTimeConverter}" ConverterParameter="0:dd MMMM yyyy г." />
                </data:DataGridTextColumn.Binding>
            </data:DataGridTextColumn>
            <data:DataGridTextColumn Header="Дата окончания периода">
                <data:DataGridTextColumn.Binding>
                    <Binding Path="Stop" Converter="{StaticResource dateTimeConverter}" ConverterParameter="0:dd MMMM yyyy г." />
                </data:DataGridTextColumn.Binding>
            </data:DataGridTextColumn>
            <data:DataGridTextColumn Header="Дата начала ввода">
                <data:DataGridTextColumn.Binding>
                    <Binding Path="StartFill" Converter="{StaticResource dateTimeConverter}" ConverterParameter="0:dd MMMM yyyy г." />
                </data:DataGridTextColumn.Binding>
            </data:DataGridTextColumn>
            <data:DataGridTextColumn Header="Дата окончания ввода">
                <data:DataGridTextColumn.Binding>
                    <Binding Path="StopFill" Converter="{StaticResource dateTimeConverter}" ConverterParameter="0:dd MMMM yyyy г." />
                </data:DataGridTextColumn.Binding>
            </data:DataGridTextColumn>
            <data:DataGridTextColumn Binding="{Binding Founds}" Header="Фонд з/п"/>
            <data:DataGridTextColumn Binding="{Binding l1}" Header="l1"/>
            <data:DataGridTextColumn Binding="{Binding l2}" Header="l2"/>
            <data:DataGridTextColumn Binding="{Binding k1}" Header="k1"/>
            <data:DataGridTextColumn Binding="{Binding k2}" Header="k2"/>
        </classes:ColumnCollection>

        <classes:ColumnCollection x:Key="AdmUnit">
            <data:DataGridTextColumn Binding="{Binding Name}" Header="Единица измерения"/>
            <data:DataGridTextColumn Binding="{Binding CharacteristicsCount}" HeaderStyle="{StaticResource infoColumnStyle}" Header="Количество показателей"/>
        </classes:ColumnCollection>

        <classes:ColumnCollection x:Key="AdmCharacteristic">
            <data:DataGridTextColumn Binding="{Binding Name}" Header="Показатель"/>
        </classes:ColumnCollection>

        <classes:ColumnCollection x:Key="AdmPersonDegree">
            <data:DataGridTemplateColumn Header="Сотрудник">
                <data:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <StackPanel VerticalAlignment="Center" Orientation="Horizontal">
                            <TextBlock Text="{Binding Path=Person.LastName}"></TextBlock>
                            <TextBlock Text=" "></TextBlock>
                            <TextBlock Text="{Binding Path=Person.FirstName}"></TextBlock>
                            <TextBlock Text=" "></TextBlock>
                            <TextBlock Text="{Binding Path=Person.Patronymic}"></TextBlock>
                        </StackPanel>
                    </DataTemplate>
                </data:DataGridTemplateColumn.CellTemplate>
            </data:DataGridTemplateColumn>
            <data:DataGridTextColumn Binding="{Binding Path=Degree.Name}" Header="Уч. степень"/>
        </classes:ColumnCollection>

        <classes:ColumnCollection x:Key="AdmDepartment">
            <data:DataGridTextColumn Binding="{Binding Path=DepartmentType.Name}" Header="Тип"/>
            <data:DataGridTextColumn Binding="{Binding Name}" Header="Отдел"/>
            <data:DataGridTextColumn Binding="{Binding Abbriviation}" Header="Аббревиатура"/>
            <data:DataGridTextColumn Binding="{Binding SID}" Header="SID"/>
            <data:DataGridTemplateColumn Header="">
                <data:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <Button Visibility="{Binding Path=SID, Converter={StaticResource emptyStringToVisibleConverter}}" Tag="{Binding}" Margin="0,0,0,0" ToolTipService.ToolTip="Найти имя по SID" Width="24" Height="24" x:Name="SIDToNameButton" Click="SIDToNameButton_Click">
                            <Image Source="/AdminModule;Component/Images/Find.png"></Image>
                        </Button>
                    </DataTemplate>
                </data:DataGridTemplateColumn.CellTemplate>
            </data:DataGridTemplateColumn>
            <data:DataGridTextColumn Binding="{Binding SIDToName, Mode=TwoWay}" Header="Имя по SID"/>
        </classes:ColumnCollection>

        <classes:ColumnCollection x:Key="AdmSection">
            <data:DataGridTextColumn Binding="{Binding Name}" Header="Раздел"/>
        </classes:ColumnCollection>

        <classes:ColumnCollection x:Key="AdmGradation">
            <data:DataGridTextColumn Binding="{Binding Name}" Header="Градация"/>
        </classes:ColumnCollection>

        <classes:ColumnCollection x:Key="AdmCategory">
            <data:DataGridTemplateColumn Header="">
                <data:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <Image Source="{Binding ImagePath}"></Image>
                    </DataTemplate>
                </data:DataGridTemplateColumn.CellTemplate>
            </data:DataGridTemplateColumn>
            <data:DataGridTextColumn Binding="{Binding Name}" Header="Категория"/>
        </classes:ColumnCollection>

        <classes:ColumnCollection x:Key="CheckBoxColumn">
            <data:DataGridTemplateColumn>
                <data:DataGridTemplateColumn.HeaderStyle>
                    <Style TargetType="dataprimitives:DataGridColumnHeader">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate>
                                    <Border BorderThickness="0,0,1,0" BorderBrush="#ffc9caca">
                                        <Grid>
                                            <Grid.Background>
                                                <LinearGradientBrush EndPoint=".7,1" StartPoint=".7,0">
                                                    <GradientStop Color="#FFFFFFFF" Offset="0.015"/>
                                                    <GradientStop Color="#F9FFFFFF" Offset="0.274"/>
                                                    <GradientStop Color="#E5FFFFFF" Offset="0.309"/>
                                                    <GradientStop Color="#FFD1D1D1" Offset="1"/>
                                                    <GradientStop Color="#FFDDE1E5" Offset="0.722"/>
                                                    <GradientStop Color="#FFDADEE2" Offset="0.983"/>
                                                </LinearGradientBrush>
                                            </Grid.Background>
                                            <CheckBox ToolTipService.ToolTip="Отметить все для удаления" x:Name="commonCheckBox" Checked="commonCheckBox_Checked" Unchecked="commonCheckBox_Checked" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Center" />
                                        </Grid>
                                    </Border>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </data:DataGridTemplateColumn.HeaderStyle>

                <data:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <CheckBox ToolTipService.ToolTip="Отметить для удаления" Loaded="CheckBox_Loaded" Checked="CheckBox_Checked" Unchecked="CheckBox_Checked" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Center" Tag="{Binding}"></CheckBox>
                    </DataTemplate>
                </data:DataGridTemplateColumn.CellTemplate>
            </data:DataGridTemplateColumn>
        </classes:ColumnCollection>
    </UserControl.Resources>
    
    <Grid x:Name="LayoutRoot" Background="White">

        <StackPanel x:Name="buttonsPanel" Orientation="Horizontal">
            <Button ToolTipService.ToolTip="Добавить" Margin="5,0,0,0" Width="24" Height="24" x:Name="addButton" Click="addButton_Click" HorizontalAlignment="Left" VerticalAlignment="Top">
                <Image Source="/AdminModule;Component/Images/Add.png"></Image>
            </Button>
            <Button IsEnabled="False" ToolTipService.ToolTip="Удалить" Margin="5,0,0,0" Width="24" Height="24" x:Name="deleteButton" Click="deleteButton_Click" HorizontalAlignment="Left" VerticalAlignment="Top">
                <Image Source="/AdminModule;Component/Images/Delete.png"></Image>
            </Button>
            <Button IsEnabled="False" ToolTipService.ToolTip="Редактировать" Margin="5,0,0,0" Width="24" Height="24" x:Name="editButton" Click="editButton_Click" HorizontalAlignment="Left" VerticalAlignment="Top">
                <Image Source="/AdminModule;Component/Images/Modify.png"></Image>
            </Button>
            <Button Height="24" Width="140" Margin="10,0,0,0" x:Name="copyButton" Visibility="Collapsed" Click="copyButton_Click" HorizontalAlignment="Left" VerticalAlignment="Top">
                <StackPanel Orientation="Horizontal">
                    <Image Margin="0,0,5,0" Source="/AdminModule;Component/Images/Copy.png"></Image>
                    <TextBlock Text="Копировать всё..."></TextBlock>
                </StackPanel>
            </Button>
        </StackPanel>

        <data:DataGrid SelectionChanged="dataGrid_SelectionChanged" Margin="0,28,0,0" x:Name="dataGrid" IsReadOnly="True" AutoGenerateColumns="False" SelectionMode="Single" Grid.ColumnSpan="2" />
        <!--<data:DataPager x:Name="dataPager" AutoEllipsis="True" HorizontalAlignment="Center" VerticalAlignment="Bottom" DisplayMode="FirstLastPreviousNextNumeric" PageSize="{Binding Path=DataPager_PageSize, Source={StaticResource settings}}" Source="{Binding Path=ItemsSource, ElementName=dataGrid}"></data:DataPager>-->
        <usercontrols:ProgressBar IsVisibility="Collapsed" VerticalAlignment="Center" HorizontalAlignment="Center" x:Name="progressBar"></usercontrols:ProgressBar>
    </Grid>
</navigation:Page>
